﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DataTransferObject
{
    [Serializable]
    public class MappedFreeTimeBlock
    {
        #region Attributes

        private List<int> workingHour;

        /// <summary>
        /// 
        /// </summary>
        private int _mappedStartDateTime;
        /// <summary>
        /// 
        /// </summary>
        private int _mappedEndDateTime;

        #endregion

        #region Essential Methods

        /// <summary>
        /// Initializes a new instance of the <see cref="FreeTimeBlock"/> class.
        /// </summary>
        public MappedFreeTimeBlock()
        {
            workingHour = new List<int>();
        }
        public MappedFreeTimeBlock(MappedFreeTimeBlock copy)
        {
            this.End = copy.End;
            this.Start = copy.Start;
            workingHour = new List<int>();
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="FreeTimeBlock"/> class.
        /// </summary>
        /// <param name="i">The i.</param>
        /// <param name="s">The s.</param>
        /// <param name="e">The e.</param>
        public MappedFreeTimeBlock(int s, int e)
        {
            _mappedStartDateTime = s;
            _mappedEndDateTime = e;
            workingHour = new List<int>();    
        }

        public List<MappedFreeTimeBlock> SplitWithMaximumLenght(int length)
        {
            int startOfNewBlock = this.Start;
            int endOfNewBlock = (startOfNewBlock / length + 1) * length /*- 1*/;
            List<MappedFreeTimeBlock> resultList = new List<MappedFreeTimeBlock>();
            while (endOfNewBlock < this.End)
            {
                resultList.Add(new MappedFreeTimeBlock(startOfNewBlock, endOfNewBlock));
                startOfNewBlock = endOfNewBlock;
                endOfNewBlock = startOfNewBlock + length;
            }

            resultList.Add(new MappedFreeTimeBlock(startOfNewBlock, this.End));

            return resultList;
        }

        /// <summary>
        /// Returns a <see cref="System.String"/> that represents this instance.
        /// </summary>
        /// <returns>
        /// A <see cref="System.String"/> that represents this instance.
        /// </returns>
        public override string ToString()
        {
            return
                "start = " + this._mappedStartDateTime + " | " +
                "end = " + this._mappedEndDateTime + " | ";
        }

        #endregion

        #region Properties

        public List<int> WorkingHour
        {
            get { return this.workingHour; }
            set { this.workingHour = value; }
        }

        public int Start
        {
            get { return _mappedStartDateTime; }
            set { _mappedStartDateTime = value; }
        }

        public int End
        {
            get { return _mappedEndDateTime; }
            set { _mappedEndDateTime = value; }
        }

        public DateTime StartDT
        {
            get
            {
                int days = _mappedStartDateTime / (24 * 60);
                int hours = (_mappedStartDateTime % (24*60)) / 60;
                int minutes = _mappedStartDateTime % 60;
                return new DateTime(1988, 1, days + 1, hours, minutes, 0);
            }

        }

        public DateTime EndDT
        {
            get
            {
                int days = _mappedEndDateTime / (24 * 60);
                int hours = (_mappedEndDateTime % (24 * 60)) / 60;
                int minutes = _mappedEndDateTime % 60;
                return new DateTime(1988, 1, days + 1, hours, minutes, 0);
            }

        }

        #endregion

        #region bổ sung
        /* @LUÂN
         * CÁC BẠN CÓ THỂ:
         * 1. COMMENT VỀ NHỮNG BỔ SUNG GÓP Ý
         * 2. VIẾT CODE ĐỀ XUẤT TRONG REGION NÀY
         * 
        */


        #endregion

    }
}
